home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Web Server / PHP.EXE / pear / PHPDoc / accessor / PhpdocDocumentAccessor.php < prev    next >
Encoding:
PHP Script  |  2001-02-18  |  7.8 KB  |  252 lines

  1. <?php
  2. /**
  3. * Base of the class and module accessor.
  4. *
  5. * @version  $Id: PhpdocDocumentAccessor.php,v 1.3 2001/02/18 15:03:05 uw Exp $
  6. */
  7. class PhpdocDocumentAccessor extends PhpdocAccessor {
  8.  
  9.     /**
  10.     * Kind of top-level container in the xml document.
  11.     * 
  12.     * Must be set by all derived classes.
  13.     *
  14.     * @var  string    
  15.     */
  16.     var $xmlkey = "";
  17.  
  18.     /**
  19.     * Returns an array with all functions.
  20.     *
  21.     * @return   array   $functions
  22.     * @access   public
  23.     * @see      getFunctionsByAccess()
  24.     */
  25.     function getFunctions() {
  26.         return $this->getElements("functions", "functionsaccess");
  27.     } // end func getFunctions
  28.     
  29.     /**
  30.     * Returns an array with all functions with a certain access (public, private) attribute.
  31.     *
  32.     * @param    string  Requested access attribute.
  33.     * @return   array   $functions
  34.     * @access   public
  35.     * @see      getFunctions()
  36.     */
  37.     function getFunctionsByAccess($access) {
  38.         return $this->getElementsByAccess($access, "functions", "functionsaccess");
  39.     } // end func getFunctionByAccess
  40.     
  41.     /**
  42.     * Returns an array with all variables.
  43.     *
  44.     * @return   array   $variables
  45.     * @access   public
  46.     * @see      getVariablesByAccess()
  47.     */
  48.     function getVariables() {
  49.         return $this->getElements("variables", "variablesaccess");
  50.     } // end func getVariables
  51.  
  52.     /**
  53.     * Returns an array with all variables with a certain access (public, private) attribute.
  54.     *
  55.     * @param    string   Requested access attribute.
  56.     * @return   array    $variables
  57.     * @access   public
  58.     * @see      getVariables()
  59.     */    
  60.     function getVariablesByAccess($access) {
  61.         return $this->getElementsByAccess($access, "variables", "variablesaccess");
  62.     } // end func getVariablesByAccess
  63.     
  64.     /**
  65.     * Returns an array of all constants.
  66.     *
  67.     * @return   array   $constants
  68.     * @access   public
  69.     * @see      getConstantsByAccess()
  70.     */
  71.     function getConstants() {
  72.         return $this->getElements("constants", "constantsaccess");
  73.     } // end func getConstants
  74.     
  75.     /**
  76.     * Returns an array of all constants with a certain access (public, private) attribute.
  77.     *
  78.     * @param    string  Requested access attribute.
  79.     * @return   array   $constants
  80.     * @see      getConstants()
  81.     * @access   public
  82.     */
  83.     function getConstantsByAccess($access) {
  84.         return $this->getElementsByAccess($access, "constants", "constantsaccess");
  85.     } // end func getConstantsByAccess
  86.     
  87.     /**
  88.     * Returns an array of all included files.
  89.     *
  90.     * @return   array    $uses
  91.     * @see      getUsesByType()
  92.     * @access   public
  93.     */
  94.     function getUses() {
  95.         return $this->getElements("uses", "usestype");
  96.     } // end func getUses
  97.  
  98.     /**
  99.     * Returns an array of all included files with a certain type (include, require...) attribute.
  100.     *
  101.     * @param    string  Requested type: include, include_once, require, require_once
  102.     * @return   array   $uses
  103.     * @access   public
  104.     */    
  105.     function getUsesByType($type) {
  106.         
  107.         $data = array();
  108.         
  109.         if (!isset($this->data["usestype"][$type])) 
  110.             return $data;
  111.             
  112.         reset($this->data["usestype"][$type]);
  113.         while (list($k, $file) = each($this->data["usestype"][$type])) {
  114.         
  115.             $data[$file] = $this->data["uses"][$file];
  116.             if ($this->freeOnGet)
  117.                 unset($this->data["uses"][$file]);
  118.                 
  119.         }
  120.         
  121.         if ($this->freeOnGet)
  122.             unset($this->data["usestype"][$type]);
  123.             
  124.         return $data;
  125.     } // end func getUsesByType
  126.     
  127.     /**
  128.     * Returns elements from the internal $data array.
  129.     * 
  130.     * The object uses this function to extract functions, variables, uses and 
  131.     * constants from an internal array. Note that this is not a public function,
  132.     * future version might access internal data structures different.
  133.     *
  134.     * @param    string  Name of the element you need: functions, variables,...
  135.     * @param    string  Name of internal element access table
  136.     * @see      $data
  137.     */
  138.     function getElements($element, $elementaccess) {
  139.         
  140.         if ($this->freeOnGet) {
  141.             
  142.             $data = $this->data[$element];
  143.             unset($this->data[$element]);
  144.             unset($this->data[$elementaccess]);
  145.             return $data;
  146.             
  147.         } else {
  148.         
  149.             $this->data[$element];
  150.             
  151.         }
  152.         
  153.     } // end func getElements
  154.  
  155.     /**
  156.     * Returns elements with a certain access type from the internal data.
  157.     *
  158.     * @param    string  Accesstype
  159.     * @param    string  element name
  160.     * @param    string  access type
  161.     * @brother  getElements()
  162.     */    
  163.     function getElementsByAccess($access, $element, $elementaccess) {
  164.         
  165.         $data = array();
  166.         
  167.         if (!isset($this->data[$elementaccess][$access]))
  168.             return $data;
  169.         
  170.         reset($this->data[$elementaccess][$access]);
  171.         while (list($k, $name) = each($this->data[$elementaccess][$access])) {
  172.             
  173.             $data[$name] = $this->data[$element][$name];
  174.             if ($this->freeOnGet)
  175.                 unset($this->data[$element][$name]);
  176.                 
  177.         }
  178.         
  179.         if ($this->freeOnGet)
  180.             unset($this->data[$elementaccess][$access]);
  181.             
  182.         return $data;
  183.     } // end func getElementsByAccess
  184.  
  185.     /**
  186.     * Adds a list of included files to the internal data array.
  187.     */
  188.     function buildUseslist() {
  189.  
  190.         $this->data["uses"] = array();
  191.         $this->data["usestype"] = array();
  192.         
  193.         if (isset($this->xml[$this->xmlkey]["uses"])) {
  194.  
  195.             if (isset($this->xml[$this->xmlkey]["uses"][0])) {        
  196.     
  197.                 reset($this->xml[$this->xmlkey]["uses"]);
  198.                 while (list($k, $data) = each($this->xml[$this->xmlkey]["uses"])) {
  199.                     $this->data["uses"][$data["file"]] = $data;
  200.                     $this->data["usestype"][$data["type"]][] = $data["file"];
  201.                 } 
  202.                 
  203.             } else {
  204.             
  205.                 $data = $this->xml[$this->xmlkey]["uses"];
  206.                 $this->data["uses"][$data["file"]] = $data;
  207.                 $this->data["usestype"][$data["type"]][] = $data["file"];
  208.  
  209.             }
  210.             
  211.             unset($this->xml[$this->xmlkey]["uses"]);            
  212.         }
  213.         
  214.     } // end func buildUseslist
  215.     
  216.     /**
  217.     * Adds a list of a certain element to the internal data array.
  218.     *
  219.     * @param    string  name of the element to add: function, variable, constant.
  220.     */
  221.     function getElementlist($element) {
  222.     
  223.         $elements = array();
  224.         $elementaccess = array();
  225.         
  226.         if (isset($this->xml[$this->xmlkey][$element])) {
  227.                                                             
  228.             if (isset($this->xml[$this->xmlkey][$element][0])) {
  229.  
  230.                 reset($this->xml[$this->xmlkey][$element]);
  231.                 while (list($k, $data) = each($this->xml[$this->xmlkey][$element])) {
  232.                     $elements[$data["name"]] = $data;
  233.                     $elementaccess[$data["access"]][] = $data["name"];    
  234.                 }    
  235.                 
  236.             } else {
  237.                 
  238.                 $data = $this->xml[$this->xmlkey][$element];
  239.                 $elements[$data["name"]] = $data;
  240.                 $elementaccess[$data["access"]][] = $data["name"];
  241.                 
  242.             }
  243.             
  244.             unset($this->xml[$this->xmlkey][$element]);
  245.             
  246.         }
  247.         
  248.         return array($elements, $elementaccess);
  249.     } // end func getElementlist
  250.  
  251. } // end class PhpdocDocumentAccessor
  252. ?>